﻿<%@ page import="java.util.List" %>
<%@ page import="com.cai.entity.Items" %>
<%@ page import="com.cai.dao.GoodsDao" %>
<%@ page import="com.cai.dao.impl.GoodsDaoImpl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    GoodsDao goodsDao = new GoodsDaoImpl();
    List<Items> itemsList = goodsDao.selectGoodsList();
    request.setAttribute("itemList", itemsList);
%>
<head>
    <title>器材列表</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="style/adminStyle.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery.js"></script>
    <script src="js/public.js"></script>
</head>
<body>
<div class="wrap">
    <div class="page-title">
        <span class="modular fl"><i></i><em>器材列表</em></span>
        <span class="modular fr"><a href="edit_product.jsp" class="pt-link-btn">+添加器材</a></span>
    </div>
    <div class="operate">
        <form>
            <select class="inline-select">
                <option>A店铺</option>
                <option>B店铺</option>
            </select>
            <input type="text" class="textBox length-long" placeholder="输入产品名称..."/>
            <input type="button" value="查询" class="tdBtn"/>
        </form>
    </div>
    <table class="list-style Interlaced">
        <tr>
            <th>序号</th>
            <th>编号</th>
            <th>名称</th>
            <th>数量</th>
            <th>类型</th>
            <th>借出</th>
            <th>归还</th>
            <th>操作</th>
        </tr>
        <!--for each循环显示物品列表-->
        <c:forEach items="${requestScope.pageList_items}" var="item" varStatus="status">
            <tr class="item">
                <td class="center">${status.count}</td>
                <td class="center">
                    <input type="checkbox" style="margin-right: 20px"/>
                    <span class="item_id ">${item.item_id}</span>
                </td>
                <td class="center item_name">${item.item_name}</td>
                <td class="center">${item.item_num}</td>
                <td class="center">${item.item_type}</td>
                <td class="center">${item.item_send}</td>
                <td class="center">${item.item_return}</td>
                <td class="center">
                    <a id="btn_update" title="编辑"><img src="images/icon_edit.gif"/></a>
                    <a title="删除" id="btn_delete"><img src="images/icon_drop.gif"/></a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <!-- BatchOperation -->
    <div style="overflow:hidden;">
        <!-- Operation -->
        <div class="BatchOperation fl">
            <input type="checkbox" id="del"/>
            <label for="del" class="btnStyle middle">全选</label>
            <input type="button" value="批量删除" class="btnStyle"/>
        </div>
        <!-- turn page -->
        <div class="turnPage center fr">
            <label>共${requestScope.totalPage_items}页&nbsp;&nbsp;共${requestScope.totalCount_items}条数据</label>
            <label>第</label>
            <c:forEach begin="1" step="1" end="${requestScope.totalPage_items}" var="count">
                <a href="<%=request.getContextPath()%>/pageItems?page=${count}">${count}</a>
            </c:forEach>
            <label>页</label>
        </div>
    </div>
</div>
<script type="text/javascript">
    //删除事件
    $(function () {
        //删除事件
        $("[id=btn_delete]").click(function () {
            $.ajax({
                url: "/cai/itemDelete",
                type: "post",
                data: {
                    //动态获取
                    item_id: $(this).parent().parent().find('.item_id').text()
                },
                success: function (data) {
                    if (parseInt(data) === 1) {
                        alert("删除成功")
                        $(this).parent().parent().hide()
                    } else if (parseInt(data) === 0) {
                        alert("物品不存在！")
                    }
                },
                error: function (data) {
                    alert("删除失败！")
                    console.log(data)
                }
            })
        })
        //编辑事件
        $("[id=btn_update]").click(function () {
            $.ajax({
                url: "/cai/itemUpdate",
                type: "post",
                data: {
                    item_id: $(this).parent().parent().find('.item_id').text(),
                    item_name: $(this).parent().parent().find('.item_name').text()
                },
                success: function (data) {
                    location.href = "edit_product.jsp"
                },
                error: function (data) {

                }
            })
        })
    })
</script>
</body>
</html>